﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Vit.Data.Test
{
    [TestClass]
    public class SqlStatementTest
    {
        [TestMethod]
        public void SelectTest()
        {
            SqlSelect sql = new SqlSelect();

            SqlObject tbl = new SqlObject("User","u");
            Assert.AreEqual("User AS u", tbl.ToSql());

            sql.Columns.AddRange(
                new SqlObject[] {
                    new SqlObject("Name"),
                    new SqlObject("Sex", "s")
                });

            sql.From.Objects.Add(tbl);

            Assert.AreEqual("SELECT Name, Sex AS s FROM User AS u", sql.ToSql());

            SqlJoin join = new SqlJoin();
            join.Join = JoinType.LeftJoin;
            join.Object = new SqlObject("UserRole", "ur");
            SqlLogic ur = new SqlLogic();
            ur.Left = new SqlCondition() { Name= "u.UserID=ur.UserID"};
            join.On.Add(ur);
        }
    }
}
